from django.db import models
from django.contrib.auth.models import User
from django.conf import settings
from django.utils import timezone
# Create your models here.
class InformationBox(models.Model):
    title = models.CharField(max_length=100,default="无标题")
    #信息标题
    TxUser = models.CharField(max_length=100,default="匿名用户")
    # 信息发出者
    RxUser = models.CharField(max_length=100)
    # 信息接收者
    content = models.TextField(default="无内容")
    #图像路径
    url = models.TextField(default="#")
    #文章内容
    published_date = models.DateTimeField(auto_now=True)
    #提交时间

class GraphService(models.Model):
    user = models.ForeignKey(User,on_delete=models.CASCADE,related_name='AnalyseData')
    #外键，连接使用者
    name = models.CharField(max_length=100)
    #患者名
    radar_data = models.JSONField(default=list)
    radar_labels = models.JSONField(default=list)
    #雷达图数据
    pie_data = models.JSONField(default=list)
    pie_labels = models.JSONField(default=list)
    #饼图数据

class PHQ9Load(models.Model):
    user = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        on_delete=models.CASCADE,
        related_name='PHQ9Load'
    )
    # 个人信息字段
    name = models.CharField(max_length=50, blank=True, default='')
    age = models.IntegerField(default=0)
    GENDER_CHOICES = [
        ('M', 'Male'),
        ('F', 'Female'),
        ('S', 'SM'),
    ]
    gender = models.CharField(
        max_length=10,
        choices=GENDER_CHOICES,
        blank=True,
        default=''
    )
    count = models.IntegerField(default=0)
    province = models.CharField(max_length=50, blank=True, default='')
    city = models.CharField(max_length=50, blank=True, default='')

    # 问卷问题字段
    question1 = models.IntegerField(default=0)
    question2 = models.IntegerField(default=0)
    question3 = models.IntegerField(default=0)
    question4 = models.IntegerField(default=0)
    question5 = models.IntegerField(default=0)
    question6 = models.IntegerField(default=0)
    question7 = models.IntegerField(default=0)
    question8 = models.IntegerField(default=0)
    question9 = models.IntegerField(default=0)

    file_path = models.CharField(max_length=100, blank=True, default='')

    # 自动时间戳
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        ordering = ['-created_at']  # 默认按创建时间倒序排列
        verbose_name = 'PHQ9Load'
        verbose_name_plural = 'PHQ9Load'
    def __str__(self):
        return f"{self.user.username}'s PHQ9 at {self.created_at}"